package com.bitoon.basketdudes.jpa;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 * @author paco FELC 2010
 */
@Entity
@Table(name = "mazo", schema = "basket")
@NamedQueries({
    @NamedQuery(name = "Mazo.findAll", query = "SELECT m FROM Mazo m"),
    @NamedQuery(name = "Mazo.findByEquipoId", query = "SELECT m FROM Mazo m WHERE m.mazoPK.equipoId = :equipoId ORDER BY m.mazoPK.cuarto, m.mazoPK.slot"),
    @NamedQuery(name = "Mazo.findByEquipoIdCartaId", query = "SELECT m FROM Mazo m WHERE m.mazoPK.equipoId = :equipoId and m.mCarta.id = :cartaId"),
    @NamedQuery(name = "Mazo.findByCuartoSlot", query = "SELECT m FROM Mazo m WHERE m.mazoPK.equipoId = :equipoId and m.mazoPK.cuarto = :cuarto and m.mazoPK.slot = :slot")})
public class Mazo implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected MazoPK mazoPK;

    @JoinColumn(name = "carta_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Carta mCarta;

    public Mazo() {
    }

    public Mazo(MazoPK mazoPK) {
        this.mazoPK = mazoPK;
    }

    public Mazo(int equipoId, short cuarto, short slot) {
        this.mazoPK = new MazoPK(equipoId, cuarto, slot);
    }

    public MazoPK getMazoPK() {
        return mazoPK;
    }

    public void setMazoPK(MazoPK mazoPK) {
        this.mazoPK = mazoPK;
    }

    public Carta getCarta() {
        return this.mCarta;
    }

    public void setCarta(Carta valor) {
        this.mCarta = valor;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (mazoPK != null ? mazoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Mazo)) {
            return false;
        }
        Mazo other = (Mazo) object;
        if ((this.mazoPK == null && other.mazoPK != null) || (this.mazoPK != null && !this.mazoPK.equals(other.mazoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bitoon.basketdudes.jpa.Mazo[mazoPK=" + mazoPK + "]";
    }

}
